package com.logistics.container.entity.domian;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.logistics.container.entity.model.ContainerSave;
import com.logistics.utils.tool.DateUtils;
import com.logistics.utils.tool.StringUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * <p>
 * 托盘主数据
 * </p>
 *
 * @author yunjian.ban
 * @since 2024-05-21
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("lgs_container")
public class Container implements Serializable {

  private static final long serialVersionUID = 1L;

  @TableId(value = "id", type = IdType.AUTO)
  private Integer id;

  private String code;

  private String name;

  private String type;

  private BigDecimal height;

  private String createOrgCode;

  private String createDepCode;

  private String creator;

  private Date createTime;

  private String updater;

  private Date updateTime;

  public static Container build(ContainerSave edit){
    Container container = new Container();
    container.setName(edit.getName());
    container.setCode(edit.getCode());
    container.setType(edit.getType());
    container.setCreateDepCode(edit.getCreateDepCode());
    container.setCreateOrgCode(edit.getCreateOrgCode());
    container.setCreator(edit.getCreator());
    container.setCreateTime(DateUtils.stringToDateFormat(edit.getCreateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS));
    container.setUpdater(edit.getUpdater());
    container.setUpdateTime(DateUtils.stringToDateFormat(edit.getUpdateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS));
    container.setHeight(StringUtils.isNotNull(edit.getHeight()) ? edit.getHeight() : BigDecimal.ZERO);
    return container;
  }
}
